﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;

namespace MShop.Core.Domain
{
    [MetadataType(typeof(ShopUsers_Validation))]
    public partial class ShopUsers
    {

        public int TradeSuccessCount
        {
            get
            {
                return this.Trade.Where(x => x.TradeStatus == (int)TradeStatus.交易成功).Count();
            }
        }

        public string FullName
        {
            get
            {
                if (!string.IsNullOrEmpty(this.TrueName))
                {
                    return this.TrueName;
                }
                return this.aspnet_Users.UserName;
            }
        }

        public string RoleName
        {
            get
            {
                if (this.RoleId.HasValue)
                {
                  var r=  aspnet_Users.aspnet_Roles.FirstOrDefault(x => x.RoleId == RoleId.Value);
                  if (r != null)
                  {
                      return r.RoleName;
                  }
                }
                return string.Empty;
            }
        }

        public string SexName
        {
            get
            {
                if (Sex.HasValue)
                    return Sex.Value ? "男" : "女";
                return string.Empty;
            }
        }

        public string AreaName
        {
            get
            {
                if (this.AreaId.HasValue)
                    return AreaGroup.Name;
                return string.Empty;
            }
        }
    }


    internal partial class ShopUsers_Validation
    {
        [DisplayName("地区")]
        public int AreaId { get; set; }

        [DisplayName("真实姓名")]
        public string TrueName { get; set; }

         [DisplayName("QQ号码")]
        public string QQ { get; set; }

        [DisplayName("Msn号码")]
        public string Msn { get; set; }

       [DisplayName("移动电话")]
        public string Mobile { get; set; }

       [DisplayName("固定电话")]
        public string Tel { get; set; }

        [DisplayName("身份证")]
       public string IdCard { get; set; }

           [DisplayName("性别")]
        public bool? Sex { get; set; }

           [DisplayName("出生日期")]
        public DateTime? Born { get; set; }
           [DisplayName("传真号码")]
        public string Fax { get; set; }

        [DisplayName("固定地址")]
        public string Address { get; set; }


        [DisplayName("会员等级")]
        public Guid? RoleId { get; set; }

        [DisplayName("备注")]
        [DataType(DataType.MultilineText)]
        public string Memo { get; set; }
    }
    
}